//
//  YYSHomePageController.m
//  FanLaiWu
//
//  Created by gonglei on 17/3/15.
//  Copyright © 2017年 yys. All rights reserved.
//

#import "YYSHomePageController.h"
#import "SlideTabBarView.h"
#import "YYSSearchController.h"
#import "YYSReadSaveController.h"
#import "FMWriteVideoController.h"
@interface YYSHomePageController ()
@end

@implementation YYSHomePageController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    SlideTabBarView *slide = [[SlideTabBarView alloc] initWithFrame:CGRectMake(0, 64, YYSScreenW, YYSScreenH) WithCount:6];
    [self.view addSubview:slide];
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    
    [self setNavi];
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    [UIView beginAnimations:nil context:nil]; // 开始动画
    [UIView setAnimationDuration:1.0]; // 动画时长
    
    /**
     *  图像向下移动
     */
    CGPoint point = view.center;
    point.y += 100;
    [view setCenter:point];
    
    [UIView commitAnimations]; // 提交动画
}
static UIView *view;
- (void)setNavi
{
    NSMutableArray *arr = [NSMutableArray array];
    for (int i = 0; i < 4; i++) {
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
        btn.tag = i;
//        [btn setTitle:@"分享" forState:UIControlStateNormal];
        
        if (i == 0) {
            [btn setImage:[UIImage imageNamed:@"shouyefenxiang"] forState:UIControlStateNormal];
        } else if (i == 1) {
            [btn setImage:[UIImage imageNamed:@"sousuo"] forState:UIControlStateNormal];
        }else if (i == 2) {
            [btn setImage:[UIImage imageNamed:@"lushipin"] forState:UIControlStateNormal];
        }else {
            [btn setImage:[UIImage imageNamed:@"liulanjilu-1"] forState:UIControlStateNormal];
        }
        UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:btn];
        [btn addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickItem:)]];
        [arr addObject:item];
    }
    
    self.navigationItem.rightBarButtonItems = arr;
    
   
    UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 10, 100, 100)];
   
    
    view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
//    view.backgroundColor = [UIColor redColor];
    [view addSubview:imageV];
    
    imageV.image = [UIImage imageNamed:@"fanlaiwu"];
//    imageV.backgroundColor =[UIColor redColor];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:view];
    
    
    
}
- (void)clickItem:(UITapGestureRecognizer *)tap
{
    if (tap.view.tag == 0) {
        [UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_WechatSession),@(UMSocialPlatformType_WechatTimeLine),@(UMSocialPlatformType_QQ),@(UMSocialPlatformType_Qzone)]];
        [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
            // 根据获取的platformType确定所选平台进行下一步操作
            //创建分享消息对象
            UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
            
            //创建网页内容对象
            NSString* thumbURL =  @"https://mobile.umeng.com/images/pic/home/social/img-1.png";
            UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"欢迎使用【友盟+】社会化组件U-Share" descr:@"欢迎使用【友盟+】社会化组件U-Share，SDK包最小，集成成本最低，助力您的产品开发、运营与推广！" thumImage:thumbURL];
            //设置网页地址
            shareObject.webpageUrl = @"http://mobile.umeng.com/social";
            
            //分享消息对象设置分享内容对象
            messageObject.shareObject = shareObject;
            
            //调用分享接口
            [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
                if (error) {
                    UMSocialLogInfo(@"************Share fail with error %@*********",error);
                }else{
                    if ([data isKindOfClass:[UMSocialShareResponse class]]) {
                        UMSocialShareResponse *resp = data;
                        //分享结果消息
                        UMSocialLogInfo(@"response message is %@",resp.message);
                        //第三方原始返回的数据
                        UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
                        
                    }else{
                        UMSocialLogInfo(@"response data is %@",data);
                    }
                }
               
            }];
        }];
        
        
    }else if (tap.view.tag == 1) {
        YYSSearchController *seach = [[YYSSearchController alloc] init];
        [self.navigationController pushViewController:seach animated:YES];

    }else if (tap.view.tag == 2) {
        FMWriteVideoController *writeVC = [[FMWriteVideoController alloc] init];
        UINavigationController *NAV = [[UINavigationController alloc] initWithRootViewController:writeVC];
        [self presentViewController:NAV animated:YES completion:nil];
        
    } else if (tap.view.tag == 3) {
        YYSReadSaveController *read = [[YYSReadSaveController alloc] init];
        [self.navigationController pushViewController:read animated:YES];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
